var app = getApp();
Page({
  data: {
    imgUrls: [
      'https://www.meijianzj.com/uploads/20201025101042dd72b5613.png'
    ],
    indicatorDots: false,
    autoplay: false,
    interval: 3000,
    duration: 800,
    res:[],
    loadingTxt: '加载中',
    noMoreData: false,
    page: 1,
    showGoTop: false,
    size: 16
  },
  onLoad: function (options) {
    this.getPorducts();
  },
  getPorducts() {
    var that = this;
    var page=this.data.page;
    var size=this.data.size;
    var cid = this.data.cid?this.data.cid:0;

    let url = app.globalData.url+'index.php?s=api/item/lists';

      wx.request({
        url: url,
        header: {
          'content-type': 'application/x-www-form-urlencoded'
        },
        method:'get',
        data: { size: size, page: page, app_id:10001},
        success: (res) => {
          if (res.data.code == 1){
            let goods = [];
            if(page == 1){
              goods = res.data.data.list;
            }else{
              goods = that.data.res.concat(res.data.data.list);
            }
           
            that.setData({
              noMoreData: false,
              res: goods
            });

            if (res.data.data.list.length < that.data.size) {

              that.setData({

                loadingTxt: '没有更多内容',

                noMoreData: true,

              });

            }
          }
        }

      })
  },
  onPageScroll: function (e) {
    if (e.scrollTop > 200) {
      this.setData({
        showGoTop: true
      })
    } else {
      this.setData({
        showGoTop: false
      })
    }
  },
  // 回到顶部
  goTop: function (e) {
    if (wx.pageScrollTo) {
      wx.pageScrollTo({
        scrollTop: 0
      })
    } else {
      wx.showModal({
        title: '提示',
        content: '当前微信版本过低，无法使用该功能，请升级到最新微信版本后重试。'
      })
    }
  },
  onPullDownRefresh: function () {
    wx.showToast({
      title: '加载中...',
      icon: 'loading'
    })

    // 初始化信息
    this.getPorducts();

    setTimeout(function () {
      wx.stopPullDownRefresh()
    }, 1000)

  },

  onReachBottom: function () {
    if (!this.data.noMoreData) {  
      wx.showToast({
        title: '加载中...',
        icon: 'loading'
      })
      this.data.page = this.data.page + 1;

      this.getPorducts(true);

    };

  }

})